using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace Coding4Fun.Phone.Controls.Binding
{
	public class TextBinding
	{
		public static readonly DependencyProperty UpdateSourceOnChangeProperty = DependencyProperty.RegisterAttached("UpdateSourceOnChange", typeof(bool), typeof(TextBinding), new PropertyMetadata(false, new PropertyChangedCallback(TextBinding.smethod_0)));
		public static bool GetUpdateSourceOnChange(DependencyObject dependencyObject_0)
		{
			return (bool)dependencyObject_0.GetValue(TextBinding.UpdateSourceOnChangeProperty);
		}
		public static void SetUpdateSourceOnChange(DependencyObject dependencyObject_0, bool value)
		{
			dependencyObject_0.SetValue(TextBinding.UpdateSourceOnChangeProperty, value);
		}
		private static void smethod_0(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_NewValue() == dependencyPropertyChangedEventArgs_0.get_OldValue())
			{
				return;
			}
			TextBinding.smethod_1(dependencyObject_0, (bool)dependencyPropertyChangedEventArgs_0.get_NewValue());
		}
		private static void smethod_1(object object_0, bool bool_0)
		{
			Type type = object_0.GetType();
			if (type == typeof(TextBox))
			{
				TextBinding.smethod_2(object_0, bool_0);
				return;
			}
			if (type == typeof(PasswordBox))
			{
				TextBinding.smethod_3(object_0, bool_0);
			}
		}
		private static void smethod_2(object object_0, bool bool_0)
		{
			TextBox textBox = object_0 as TextBox;
			if (textBox == null)
			{
				return;
			}
			if (bool_0)
			{
				textBox.add_TextChanged(new TextChangedEventHandler(TextBinding.smethod_4));
				return;
			}
			textBox.remove_TextChanged(new TextChangedEventHandler(TextBinding.smethod_4));
		}
		private static void smethod_3(object object_0, bool bool_0)
		{
			PasswordBox passwordBox = object_0 as PasswordBox;
			if (passwordBox == null)
			{
				return;
			}
			if (bool_0)
			{
				passwordBox.add_PasswordChanged(new RoutedEventHandler(TextBinding.smethod_4));
				return;
			}
			passwordBox.remove_PasswordChanged(new RoutedEventHandler(TextBinding.smethod_4));
		}
		private static void smethod_4(object sender, RoutedEventArgs e)
		{
			DependencyProperty dependencyProperty = TextBinding.smethod_5(sender);
			if (dependencyProperty == null)
			{
				return;
			}
			BindingExpression bindingExpression = ((FrameworkElement)sender).GetBindingExpression(dependencyProperty);
			if (bindingExpression != null)
			{
				bindingExpression.UpdateSource();
			}
		}
		private static DependencyProperty smethod_5(object object_0)
		{
			Type type = object_0.GetType();
			DependencyProperty result = null;
			if (type == typeof(TextBox))
			{
				result = TextBox.TextProperty;
			}
			else
			{
				if (type == typeof(PasswordBox))
				{
					result = PasswordBox.PasswordProperty;
				}
			}
			return result;
		}
	}
}
